package com.iee.lambda;

import org.apache.commons.lang3.BooleanUtils;

import java.util.Objects;

public class Objectss {

    public static void main(String[] args) {
        // 不为空判断
        Integer integer1 = new Integer(128);
        integer1 = null;
//        Objects.requireNonNull(integer1, "参数不能为空");   // 抛出空指针， 提示 "参数不能为空"
        System.out.println(integer1);

        // 判断两个对象是否相等
        Integer integer11 = new Integer(1);
        Integer integer22 = new Integer(1);
        System.out.println(Objects.equals(integer11, integer22));  // true

        Integer a1 = new Integer(1);
        Long a2 = new Long(1);
        System.out.println(Objects.equals(a1, a2));  // false

        String str = new String("abc");
        System.out.println(Objects.hashCode(str));  // 96354

        // 判断true或false
        Boolean aBoolean = Boolean.TRUE;
        System.out.println(BooleanUtils.isTrue(aBoolean)); // true
        System.out.println(BooleanUtils.isFalse(aBoolean)); // false
        // 判断不为true或不为false
        Boolean aBoolean1 = new Boolean(true);
        Boolean aBoolean11 = null;
        System.out.println(BooleanUtils.isNotTrue(aBoolean1)); // false
        System.out.println(BooleanUtils.isNotTrue(aBoolean11)); // true
        System.out.println(BooleanUtils.isNotFalse(aBoolean1)); // true
        System.out.println(BooleanUtils.isNotFalse(aBoolean11)); // true

        // 转换成数字 如果你想将true转换成数字1，false转换成数字0，可以使用toInteger方法：
        Boolean aa1 = Boolean.TRUE;
        Boolean aa2 = Boolean.FALSE;
        System.out.println(BooleanUtils.toInteger(aa1));
        System.out.println(BooleanUtils.toInteger(aa2));

        // Boolean转换成布尔值
        Boolean bb1 = new Boolean(true);
        Boolean bb2 = null;
        System.out.println(BooleanUtils.toBoolean(bb1));  // true
        System.out.println(BooleanUtils.toBoolean(bb2)); // false
        System.out.println(BooleanUtils.toBooleanDefaultIfNull(bb1, false));  // true
    }

}
